package record;

import java.sql.Timestamp;
import java.util.Date;

import util.MetaData;
import geodata.BoreData;
import geodata.BuildingData;
import geodata.GeologicalData;

/**
 * A class that represents a project, containing all information required to be a geothermal project.
 * @author Sean Freitag
 * @author Stephan Jossie
 * @author Jacob Freemyer
 *
 */
@SuppressWarnings("serial")
public class ProjectRecord implements Record,Comparable<ProjectRecord>
{
	/**
	 * The name of this project
	 */
	private String name;
	/**
	 * The path of this project in the file system
	 */
	private String path;
	
	/**
	 * An indicator of whether the bore requirements are complete
	 */
	private boolean boreRequirementsComplete = false;
	/**
	 * An indicator of whether the geothermal requirements are complete
	 */
	private boolean geothermalRequirementsComplete = false;
	/**
	 * An indicator of whether the building requirements are complete
	 */
	private boolean buildingRequirementsComplete = false;
	
	/**
	 * The building data of this project
	 */
	private BuildingData data;
	
	/**
	 * The geological data of this project
	 */
	private GeologicalData geodata;
	/**
	 * The bore data of this project
	 */
	private BoreData boreData;
	/**
	 * This project's metadata
	 */
	private MetaData metaData;
	
	/**
	 * Gets the bore data of this project
	 * @return the project's bore data
	 */
	public BoreData getBoreData()
	{
		return boreData;
	}

	/**
	 * Creates a new instance of ProjectRecord that holds all the information required for the geothermal project
	 * @param projName
	 * 		Name of project
	 */
	public ProjectRecord(String projName)
	{
		name = projName;
		data = new BuildingData();
		geodata = new GeologicalData();
		boreData = new BoreData();
		metaData = new MetaData(new Timestamp(new Date().getTime()));
	}
	
	/**
	 * Changes the last saved date of the metadata
	 * @param stamp the new date stamp of the metadata
	 */
	public void changeLastSaved(Timestamp stamp)
	{
		metaData.setLastSaved(stamp);
	}
	
	/**
	 * Changes the last opened date of the metadata
	 * @param stamp the new date stamp of the metadata
	 */
	public void changeLastOpened(Timestamp stamp)
	{
		metaData.setLastOpened(stamp);
	}
	
	/**
	 * Gets the project's metadata
	 * @return the project metadata
	 */
	public MetaData getMetaData()
	{
		return metaData;
	}
	
	/**
	 * Determines whether all the data for Bore Requirements have been completed by the user.
	 * @return
	 * 		True - Complete
	 * 		False - Incomplete 
	 */
	public boolean isBoreRequirementsComplete()
	{
		return boreRequirementsComplete;
	}

	/**
	 * Sets whether or not Bore Requirements have been completed
	 * @param boreRequirementsComplete
	 * 		True - Complete
	 * 		False - Incomplete
	 */
	public void setBoreRequirementsComplete(boolean boreRequirementsComplete)
	{
		this.boreRequirementsComplete = boreRequirementsComplete;
	}

	/**
	 * Determines whether all the data for Geothermal Requirements have been completed by the user.
	 * @return
	 * 		True - Complete
	 * 		False - Incomplete 
	 */
	public boolean isGeothermalRequirementsComplete()
	{
		return geothermalRequirementsComplete;
	}

	/**
	 * Sets whether or not Geothermal Requirements have been completed
	 * @param geothermalRequirementsComplete
	 * 		True - Complete
	 * 		False - Incomplete
	 */
	public void setGeothermalRequirementsComplete(
			boolean geothermalRequirementsComplete)
	{
		this.geothermalRequirementsComplete = geothermalRequirementsComplete;
	}

	/**
	 * Determines whether all the data for Building Requirements have been completed by the user.
	 * @return
	 * 		True - Complete
	 * 		False - Incomplete 
	 */
	public boolean isBuildingRequirementsComplete()
	{
		return buildingRequirementsComplete;
	}

	/**
	 * Sets whether or not Building Requirements have been completed
	 * @param buildingRequirementsComplete
	 * 		True - Complete
	 * 		False - Incomplete
	 */
	public void setBuildingRequirementsComplete(boolean buildingRequirementsComplete)
	{
		this.buildingRequirementsComplete = buildingRequirementsComplete;
	}

	/**
	 * Gets the name of the project.
	 * @return
	 * 		Name of the project.
	 */
	public String getName()
	{
		return name;
	}
	
	/**
	 * Returns the path of the project
	 * @return the path in the file system of this project
	 */
	public String getPath()
	{
		return path;
	}
	
	/**
	 * @see Object#toString()
	 */
	@Override
	public String toString()
	{
		return name;
	}

	/**
	 * @see Object#equals(Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ProjectRecord other = (ProjectRecord) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	/**
	 * Gets the building data
	 * @return the building data
	 */
	public BuildingData getBuildingData()
	{
		return data;
	}

	/**
	 * Gets the geological data
	 * @return the geological data 
	 */
	public GeologicalData getGeoData() {
		return geodata;
	}

	/**
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(ProjectRecord arg0) {
		return name.compareTo(arg0.name);
	}	
}
